//
//  statusCell.m
//  1-MushroomStreet-自定义tabbar
//
//  Created by xmg on 16/1/27.
//  Copyright © 2016年 grx. All rights reserved.
//

#import "statusCell.h"
#import "StatusListModel.h"
#import <UIImageView+WebCache.h>

@interface statusCell ()
@property (weak, nonatomic) IBOutlet UILabel *text_Label;
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *creatTimeLabel;
@property (weak, nonatomic) IBOutlet UILabel *fromLabel;
@property (weak, nonatomic) IBOutlet UIButton *repostsButton;
@property (weak, nonatomic) IBOutlet UIButton *commentsButton;
@property (weak, nonatomic) IBOutlet UIButton *attitudesButton;
@property (weak, nonatomic) IBOutlet UIImageView *avatarImageView;
@property (weak, nonatomic) IBOutlet UIImageView *mbrankImageView;

@end

@implementation statusCell



- (void)setModel:(StatusListModel *)model{
    _model = model;
    
    self.text_Label.text = model.text;
    self.creatTimeLabel.text = model.created_at;
    if (model.source.length != 0) {        
        self.fromLabel.text = [self createSourceStr:model.source];
    }
    
    self.nameLabel.text = model.user.screen_name;
    
    
    if (model.user.verifiedImage.length != 0) {
        self.avatarImageView.image = [UIImage imageNamed:model.user.verifiedImage];
    }
    
    if (model.user.mbrankImage.length != 0) {
        self.mbrankImageView.image = [UIImage imageNamed:model.user.mbrankImage];
    }
    

    
    
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.user.profile_image_url]];
    
    [self.repostsButton setTitle:[NSString stringWithFormat:@"%zd",model.reposts_count] forState:UIControlStateNormal];
    [self.commentsButton setTitle:[NSString stringWithFormat:@"%zd",model.comments_count] forState:UIControlStateNormal];
    [self.attitudesButton setTitle:[NSString stringWithFormat:@"%zd",model.attitudes_count] forState:UIControlStateNormal];
}


//微博来源处理
- (NSString *)createSourceStr:(NSString *)source{
    
    //1.从什么地方开始截取
    NSUInteger loaction = [source rangeOfString:@">"].location + 1;
    
    //2.截取的长度是多少
    NSUInteger length = [source rangeOfString:@"<" options:NSBackwardsSearch].location - loaction;
    
    //3.确定截取范围
    NSRange range = NSMakeRange(loaction, length);
    
    //4.获取截取的字符串
    NSString *result = [source substringWithRange:range];
    
    return result;
}


@end
